<template>
    <div class="box">
        <div class="playground">
            <GameMapVue></GameMapVue>
        </div>
        <div class="keystroke" v-if="$store.state.pk.status === 'playing'">
            <div class="row">
                <div class="offset-4">
                    <button type="button" @click="keystrokeMove(0)" style="margin-left: 18px;" class="btn btn-success">上</button>
                </div>
            </div>
            <div class="row"  style="margin-top: 5px;">
                <div class="offset-2">
                    <button type="button" @click="keystrokeMove(3)" style="margin-right: 10px;" class="btn btn-primary">左</button>
                    <button type="button" @click="keystrokeMove(2)" style="margin-right: 10px;" class="btn btn-info">下</button>
                    <button type="button" @click="keystrokeMove(1)" class="btn btn-secondary">右</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import GameMapVue from './GameMap.vue'
    import {useStore} from 'vuex'
    export default{
        components: {
            GameMapVue
        },
        setup() {
            let store = useStore();
            let keystrokeMove = (d) => {
                store.state.pk.socket.send(JSON.stringify({
                    event:'move',
                    direction:d 
                }))  
            }
            return {
                keystrokeMove,
            }
        },
    }
</script>

<style scoped>
    div.playground{
        width: 60vw;
        height: 70vh;
        margin: 20px auto;
    }
    div.keystroke{
        display: none;
    }
    @media screen and (max-width: 430px) and (min-width: 300px) {
        .box{
            overflow-y: hidden;
        }
        div.playground{
            width: 80vw;
            height: 60vh;
            margin: 5px auto;
        }
        div.keystroke{
            width: 100%;
            height: 120px;
            display: block;
        }
        button{
            width: 20%;
        }
    }
    @media screen and (max-width: 590px) and (min-width: 430px){
        .box{
            overflow-y: hidden;
        }
        div.playground{
            width: 80vw;
            height: 60vh;
            margin: 5px auto;
        }
        div.keystroke{
            width: 100%;
            height: 120px;
            display: block;
        }
        button{
            width: 20%;
        }
    }
</style>